﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using tmAsk.Common;

namespace tmAsk.Manager
{
    public partial class Admin_del : System.Web.UI.Page
    {
        function make_htm = new function();//继承类
        tmAsk.Data.MakehtmlSQL SQL = new tmAsk.Data.MakehtmlSQL();
        protected void Page_Load(object sender, EventArgs e)
        {
            function.CheckAdminLogin();

            string T = Request.Params["T"];
            string id = Request.Params["id"];

            switch (T)
            {
                case "b_info":
                    T_B_info(id);
                    break;
                case "b_makehtml":
                    T_B_makehtml(id);
                    break;
                case "b_msg":
                    T_B_msg(id);
                    break;
                case "b_askClass":
                    T_B_askClass(id);
                    break;
                case "b_userLevel":
                    T_b_userLevel(id);
                    break;
                case "b_userLevel_all":
                    T_b_userLevel_all(id);
                    break;
                case "b_file":
                    T_B_file(id);
                    break;
                case "b_user":
                    T_B_user(id);
                    break;
                case "b_user_all":
                    T_B_user_all(id);
                    break;
                case "b_admin":
                    T_B_admin(id);
                    break;
                case "b_ask":
                    T_B_ask(id);
                    break;
                case "b_askall":
                    T_B_ask_all(id);
                    break;
                case "b_recycle":
                    T_B_recycle(id);
                    break;
                case "b_review":
                    T_B_review(id);
                    break;
                case "b_hotKeyword":
                    T_B_hotKeyword(id);
                    break;
                case "b_hotKeyword_all":
                    T_B_hotKeyword_all(id);
                    break;
                case "b_news":
                    T_B_news(id);
                    break;
                case "b_news_all":
                    T_B_news_all(id);
                    break;
                case "b_help":
                    T_B_help(id);
                    break;
                case "b_help_all":
                    T_B_help_all(id);
                    break;
                case "b_search":
                    T_B_search(id);
                    break;
                case "api":
                    T_B_api(id);
                    break;
                case "b_links":
                    T_B_links(id);
                    break;
                case "b_links_all":
                    T_B_links_all(id);
                    break;
            }
        }

        /// <summary>
        /// 基本信息设置
        /// </summary>
        /// <param name="id"></param>
        private void T_B_info(string id)
        {
            if (id == "" || id == null)//id为空 删除所有
            {
                id = Request.Form["i_id"];//去页面找id
                if (id == null || id == "")//如果还找不到
                {

                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)//循环删除
                {
                    SQL.ExecuteSql("delete from B_info where i_id=" + delid[i]);
                }
            }
            else
            {
                string sql = "delete from B_info where i_id=" + id;
                int i = SQL.ExecuteSql(sql);
                if (i <= 0)
                {
                    Response.Write(function.alert_text(4, "删除失败", ""));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_info.html"));
        }

        /// <summary>
        /// 生成静态页设置
        /// </summary>
        /// <param name="id"></param>
        private void T_B_makehtml(string id)
        {
            if (id == "" || id == null)
            {
                id = Request.Form["m_id"];//去页面找id
                if (id == null || id == "")//如果还找不到
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)//循环删除
                {
                    SQL.ExecuteSql("delete from B_makehtml where m_id=" + delid[i]);
                }
            }
            else
            {
                string sql = "delete from B_makehtml where m_id=" + id;
                int i = SQL.ExecuteSql(sql);
                if (i <= 0)
                {
                    Response.Write(function.alert_text(4, "删除失败", ""));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_set.html"));
        }

        /// <summary>
        /// 站内短信管理
        /// </summary>
        /// <param name="id"></param>
        private void T_B_msg(string id)
        {
            if (id == "" || id == null)
            {
                id = Request.Form["m_id"];//去页面找id
                if (id == null || id == "")//如果还找不到
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)//循环删除
                {
                    SQL.ExecuteSql("delete from B_msg where m_id=" + delid[i]);
                }
            }
            else
            {
                string sql = "delete from B_msg where m_id=" + id;
                int i = SQL.ExecuteSql(sql);
                if (i <= 0)
                {
                    Response.Write(function.alert_text(4, "删除失败", ""));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_msg.html"));
        }

        /// <summary>
        /// 问题分类设置
        /// </summary>
        /// <param name="id"></param>
        private void T_B_askClass(string id)
        {
            //先判断要删除的分类有没有子分类
            DataTable dt = SQL.GetList("B_askClass", "1=1", "a_parentid").Tables[0];
            if (dt.Rows.Count > 0)
            {
                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    if (dt.Rows[j]["a_parentid"].ToString().Equals(id))
                    {
                        Response.Write(function.alert_text(4, "删除失败，请先将子分类删除！", ""));
                        return;
                    }
                }
            }
            string sql = "delete from B_askClass where a_classid=" + id;
            int i = SQL.ExecuteSql(sql);
            if (i > 0)
            {
                Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_class_ask.html"));
                return;
            }
            else
            {
                Response.Write(function.alert_text(4, "删除失败", ""));
                return;
            }
        }

        /// <summary>
        /// 会员等级设置
        /// </summary>
        /// <param name="id"></param>
        private void T_b_userLevel(string id)
        {
            DataTable dtUser = new DataTable();
            DataTable dtUserLevel = new DataTable();
            if (id == "" || id == null)
            {
                id = Request.Form["u_id"];//去页面找id

                if (id == null || id == "")//如果还找不到
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)
                {
                    //先根据用户等级ID在用户等级表中找到该ID的等级
                    dtUserLevel = SQL.GetList("b_userLevel", "u_id=" + delid[i], "u_level").Tables[0];
                    for (int k = 0; k < dtUserLevel.Rows.Count; k++)
                    {
                        //循环查找USER表中有没有用户占用该等级
                        dtUser = SQL.GetList("B_user", "u_level=" + dtUserLevel.Rows[k]["u_level"], "u_level").Tables[0];
                        //如果所有用户的等级均不为该ID的等级 则可以删除该等级
                        if (dtUser.Rows.Count > 0)//不能删除
                        {
                            Response.Write(function.alert_text(2, "删除失败，仍有用户占用此等级！", "admin_url.aspx?template=template/t_admin_user_level.html"));
                            return;
                        }
                        else
                        {
                            for (int j = 0; j < delid.Length; j++)
                            {
                                SQL.ExecuteSql("delete from b_userLevel where u_id=" + delid[j]);
                            }
                        }
                    }
                    break;
                }
            }
            else
            {
                dtUserLevel = SQL.GetList("b_userLevel", "u_id=" + id, "u_level").Tables[0];
                for (int k = 0; k < dtUserLevel.Rows.Count; k++)
                {
                    dtUser = SQL.GetList("B_user", "u_level=" + dtUserLevel.Rows[k]["u_level"], "u_level").Tables[0];
                }
                if (dtUser.Rows.Count <= 0)
                {
                    string sql = "delete from b_userLevel where u_id=" + id;
                    int i = SQL.ExecuteSql(sql);
                    if (i <= 0)
                    {
                        Response.Write(function.alert_text(4, "删除失败", ""));
                        return;
                    }
                }
                else
                {
                    Response.Write(function.alert_text(2, "删除失败，仍有用户占用此等级！", "admin_url.aspx?template=template/t_admin_user_level.html"));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_user_level.html"));
        }

        /// <summary>
        /// 会员等级设置
        /// </summary>
        /// <param name="id"></param>
        private void T_b_userLevel_all(string id)
        {
            DataTable dtUser = new DataTable();
            DataTable dtUserLevel = new DataTable();
            if (id == "" || id == null)
            {
                //id = Request.Form["u_id"];//去页面找id

                id = string.Join(",", (string[])Request.Form.GetValues("checkbox"));

                if (id == null || id == "")//如果还找不到
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)
                {
                    //先根据用户等级ID在用户等级表中找到该ID的等级
                    dtUserLevel = SQL.GetList("b_userLevel", "u_id=" + delid[i], "u_level").Tables[0];
                    for (int k = 0; k < dtUserLevel.Rows.Count; k++)
                    {
                        //循环查找USER表中有没有用户占用该等级
                        dtUser = SQL.GetList("B_user", "u_level=" + dtUserLevel.Rows[k]["u_level"], "u_level").Tables[0];
                        //如果所有用户的等级均不为该ID的等级 则可以删除该等级
                        if (dtUser.Rows.Count > 0)//不能删除
                        {
                            Response.Write(function.alert_text(2, "删除失败，仍有用户占用此等级！", "admin_url.aspx?template=template/t_admin_user_level.html"));
                            return;
                        }
                        else
                        {
                            for (int j = 0; j < delid.Length; j++)
                            {
                                SQL.ExecuteSql("delete from b_userLevel where u_id=" + delid[j]);
                            }
                        }
                    }
                    break;
                }
            }
            else
            {
                dtUserLevel = SQL.GetList("b_userLevel", "u_id=" + id, "u_level").Tables[0];
                for (int k = 0; k < dtUserLevel.Rows.Count; k++)
                {
                    dtUser = SQL.GetList("B_user", "u_level=" + dtUserLevel.Rows[k]["u_level"], "u_level").Tables[0];
                }
                if (dtUser.Rows.Count <= 0)
                {
                    string sql = "delete from b_userLevel where u_id=" + id;
                    int i = SQL.ExecuteSql(sql);
                    if (i <= 0)
                    {
                        Response.Write(function.alert_text(4, "删除失败", ""));
                        return;
                    }
                }
                else
                {
                    Response.Write(function.alert_text(2, "删除失败，仍有用户占用此等级！", "admin_url.aspx?template=template/t_admin_user_level.html"));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_user_level.html"));
        }

        /// <summary>
        /// 上传附件管理
        /// </summary>
        /// <param name="id"></param>
        private void T_B_file(string id)
        {
            string sql = "delete from B_image where i_id=" + id;
            int i = SQL.ExecuteSql(sql);
            if (i > 0)
            {
                Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_file.html"));
                return;
            }
            else
            {
                Response.Write(function.alert_text(4, "删除失败", ""));
                return;
            }
        }

        /// <summary>
        /// 注册用户管理
        /// </summary>
        /// <param name="id"></param>
        private void T_B_user(string id)
        {
            string target = Request["target"];
            if (id == "" || id == null)
            {
                id = Request.Form["u_id"];
                if (id == "" || id == null)
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)//循环删除
                {
                    DeleteUserRelated(delid[i]);
                }
            }
            else
            {
                DeleteUserRelated(id);
            }
            //跳转
            if ("tourists" == target)
            {
                Response.Redirect("admin_url.aspx?template=template/t_admin_tourists.html");
                return;
            }
            Response.Redirect("admin_url.aspx?template=template/t_admin_user.html");
        }

        /// <summary>
        /// 注册用户管理
        /// </summary>
        /// <param name="id"></param>
        private void T_B_user_all(string id)
        {
            string target = Request["target"];
            if (id == "" || id == null)
            {
                //id = Request.Form["u_id"];

                id = string.Join(",", (string[])Request.Form.GetValues("checkbox"));

                if (id == "" || id == null)
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)//循环删除
                {
                    DeleteUserRelated(delid[i]);
                }
            }
            else
            {
                DeleteUserRelated(id);
            }
            //跳转
            if ("tourists" == target)
            {
                Response.Redirect("admin_url.aspx?template=template/t_admin_tourists.html");
                return;
            }
            Response.Redirect("admin_url.aspx?template=template/t_admin_user.html");
        }

        /// <summary>
        /// 删除用户相关的文件以及上传图片和视频
        /// </summary>
        /// <param name="uid"></param>
        private void DeleteUserRelated(string uid)
        {
            DataTable dt = null;
            try
            {   //回答表
                dt = SQL.GetList("select i_path from b_image where i_model=(select r_id from b_review where r_userid=" + uid + ")").Tables[0];
                File.Delete(Server.MapPath(dt.Rows[0][0].ToString()));
                SQL.ExecuteSql("delete from b_review where r_userid=" + uid);
                dt = null;
            }
            catch
            { }
            try
            {   //短消息
                SQL.ExecuteSql("delete from b_msg where m_acceptuser=" + uid);
            }
            catch
            { }
            try
            {   //问题表
                dt = SQL.GetList("select a_img,a_upload from b_ask where u_id=" + uid).Tables[0];
                File.Delete(Server.MapPath(dt.Rows[0][0].ToString()));
                File.Delete(Server.MapPath(dt.Rows[0][1].ToString()));
                SQL.ExecuteSql("delete from b_ask where u_id=" + uid);
                dt = null;
            }
            catch
            { }
            try
            {
                dt = SQL.GetList("select u_img from b_user where u_id=" + uid).Tables[0];
                if (dt.Rows[0][0].ToString().ToLower() != alldata.Config_defaultimg.ToString())
                {
                    File.Delete(Server.MapPath(dt.Rows[0][0].ToString()));
                }
            }
            catch
            { }
            SQL.ExecuteSql("delete from b_user where u_id=" + uid);
        }

        /// <summary>
        /// 删除管理员
        /// </summary>
        /// <param name="id"></param>
        private void T_B_admin(string id)
        {
            if (id == "" || id == null)
            {
                Response.Write(function.alert_text(4, "错误，为选择数据或ID为空！", ""));
                return;
            }
            string sql = "delete from B_admin where a_id=" + id;
            int i = SQL.ExecuteSql(sql);
            if (i > 0)
            {
                Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_administrator.html"));
                return;
            }
            else
            {
                Response.Write(function.alert_text(4, "删除失败", ""));
                return;
            }
        }

        /// <summary>
        /// 删除问题
        /// </summary>
        /// <param name="id"></param>
        private void T_B_ask(string id)
        {
            if (id == "" || id == null)
            {
                id = Request.Form["a_id"];//去页面找id
                if (id == null || id == "")//如果还找不到
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)//循环删除
                {
                    SQL.ExecuteSql("delete from B_ask where a_id=" + delid[i]);
                    // File.Delete(Request.MapPath("../ask/a_" + make_htm.Md5(delid[i]) + ".html"));
                    DataTable dtReview = SQL.GetList("select r_id from B_review where a_id=" + delid[i]).Tables[0];
                    if (dtReview.Rows.Count > 0)
                    {
                        for (int j = 0; j < dtReview.Rows.Count; j++)
                        {
                            SQL.ExecuteSql("delete from B_review where r_id=" + dtReview.Rows[j]["r_id"]);
                        }
                    }
                }
            }
            else
            {
                int i = SQL.ExecuteSql("delete from B_ask where a_id=" + id);
                SQL.ExecuteSql("delete from B_ask where a_id=" + id);
                // File.Delete(Request.MapPath("../Ask/A_" + make_htm.Md5(id) + ".html"));
                DataTable dtReview = SQL.GetList("select r_id from B_review where a_id=" + id).Tables[0];
                if (dtReview.Rows.Count > 0)
                {
                    for (int j = 0; j < dtReview.Rows.Count; j++)
                    {
                        SQL.ExecuteSql("delete from B_review where r_id=" + dtReview.Rows[j]["r_id"].ToString());
                    }
                }
                if (i <= 0)
                {
                    Response.Write(function.alert_text(4, "删除失败", ""));
                    return;
                }
            }

            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_ask.html"));

        }

        /// <summary>
        /// 批量删除问题
        /// </summary>
        /// <param name="id"></param>
        private void T_B_ask_all(string id)
        {
            if (id == "" || id == null)
            {
                // id = Request.Form.GetValues("checkbox");//去页面找id

                id = string.Join(",", (string[])Request.Form.GetValues("checkbox"));

                if (id == null || id == "")//如果还找不到
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)//循环删除
                {
                    SQL.ExecuteSql("delete from B_ask where a_id=" + delid[i]);
                    // File.Delete(Request.MapPath("../Ask/A_" + make_htm.Md5(delid[i]) + ".html"));
                    DataTable dtReview = SQL.GetList("select r_id from B_review where a_id=" + delid[i]).Tables[0];
                    if (dtReview.Rows.Count > 0)
                    {
                        for (int j = 0; j < dtReview.Rows.Count; j++)
                        {
                            SQL.ExecuteSql("delete from B_review where r_id=" + dtReview.Rows[j]["r_id"]);
                        }
                    }
                }
            }
            else
            {
                int i = SQL.ExecuteSql("delete from B_ask where a_id=" + id);
                SQL.ExecuteSql("delete from B_ask where a_id=" + id);
                // File.Delete(Request.MapPath("../Ask/A_" + make_htm.Md5(id) + ".html"));
                DataTable dtReview = SQL.GetList("select r_id from B_review where a_id=" + id).Tables[0];
                if (dtReview.Rows.Count > 0)
                {
                    for (int j = 0; j < dtReview.Rows.Count; j++)
                    {
                        SQL.ExecuteSql("delete from B_review where r_id=" + dtReview.Rows[j]["r_id"].ToString());
                    }
                }
                if (i <= 0)
                {
                    Response.Write(function.alert_text(4, "删除失败", ""));
                    return;
                }
            }

            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_ask.html"));
        }

        /// <summary>
        /// 回收站管理-同意删除
        /// </summary>
        /// <param name="id"></param>
        private void T_B_recycle(string id)
        {   //要同时删除回复、静态页
            DataTable reviewDT;
            if (id == "" || id == null)
            {
                id = Request.Form["a_id"];
                if (id == "" || id == null)
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)
                {
                    reviewDT = SQL.GetList("B_review", "a_id=" + delid[i], "r_id").Tables[0];
                    for (int j = 0; j < reviewDT.Rows.Count; j++)
                    {
                        SQL.ExecuteSql("delete from B_review where r_id=" + reviewDT.Rows[j]["r_id"]);
                        // File.Delete(Request.MapPath("../Review/Review" + id + ".html"));
                    }
                    int k = SQL.ExecuteSql("delete from B_ask where a_id=" + delid[i]);
                    // File.Delete(Request.MapPath("../Ask/ask" + id + ".html"));
                    if (k <= 0)
                    {
                        Response.Write(function.alert_text(4, "删除回复失败", ""));
                        return;
                    }
                }
            }
            else
            {
                reviewDT = SQL.GetList("B_review", "a_id=" + id, "r_id").Tables[0];
                for (int i = 0; i < reviewDT.Rows.Count; i++)//删除所有回复
                {
                    SQL.ExecuteSql("delete from B_review where r_id=" + reviewDT.Rows[i]["r_id"]);
                    //  File.Delete(Request.MapPath("../Review/Review" + id + ".html"));
                }
                //根据ID删除问题
                int l = SQL.ExecuteSql("delete from B_ask where a_id=" + id);
                //  File.Delete(Request.MapPath("../Ask/ask" + id + ".html"));
                if (l <= 0)
                {
                    Response.Write(function.alert_text(4, "删除回复失败", ""));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_recycle.html"));
        }

        /// <summary>
        /// 删除回复
        /// </summary>
        /// <param name="id"></param>
        private void T_B_review(string id)
        {
            if (id == "" || id == null)
            {
                id = Request.Form["r_id"];
                if (id == "" || id == null)
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)//循环删除
                {
                    SQL.ExecuteSql("delete from B_review where r_id=" + delid[i]);
                }
            }
            else
            {
                int i = SQL.ExecuteSql("delete from B_review where r_id=" + id);
                if (i <= 0)
                {
                    Response.Write(function.alert_text(4, "删除失败", ""));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_review.html"));
        }

        /// <summary>
        /// 删除热词
        /// </summary>
        /// <param name="id"></param>
        private void T_B_hotKeyword(string id)
        {
            if (id == "" || id == null)
            {
                id = Request.Form["h_id"];
                if (id == "" || id == null)
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)//循环删除
                {
                    SQL.ExecuteSql("delete from B_hotKeyword where h_id=" + delid[i]);
                }
            }
            else
            {
                int i = SQL.ExecuteSql("delete from B_hotKeyword where h_id=" + id);
                if (i <= 0)
                {
                    Response.Write(function.alert_text(4, "删除失败", ""));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_hotKeyword.html"));
        }

        /// <summary>
        /// 删除热词
        /// </summary>
        /// <param name="id"></param>
        private void T_B_hotKeyword_all(string id)
        {
            if (id == "" || id == null)
            {
                //id = Request.Form["h_id"];

                id = string.Join(",", (string[])Request.Form.GetValues("checkbox"));

                if (id == "" || id == null)
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)//循环删除
                {
                    SQL.ExecuteSql("delete from B_hotKeyword where h_id=" + delid[i]);
                }
            }
            else
            {
                int i = SQL.ExecuteSql("delete from B_hotKeyword where h_id=" + id);
                if (i <= 0)
                {
                    Response.Write(function.alert_text(4, "删除失败", ""));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_hotKeyword.html"));
        }

        /// <summary>
        /// 删除公告
        /// </summary>
        /// <param name="id"></param>
        private void T_B_news(string id)
        {
            if (id == "" || id == null)
            {
                id = Request.Form["n_id"];
                if (id == "" || id == null)
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)
                {
                    SQL.ExecuteSql("delete from B_news where n_id=" + delid[i]);
                }
            }
            else
            {
                int i = SQL.ExecuteSql("delete from B_news where n_id=" + id);
                if (i <= 0)
                {
                    Response.Write(function.alert_text(4, "删除失败", ""));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_news.html"));
        }

        /// <summary>
        /// 删除公告
        /// </summary>
        /// <param name="id"></param>
        private void T_B_news_all(string id)
        {
            if (id == "" || id == null)
            {
                //id = Request.Form["n_id"];

                id = string.Join(",", (string[])Request.Form.GetValues("checkbox"));

                if (id == "" || id == null)
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)
                {
                    SQL.ExecuteSql("delete from B_news where n_id=" + delid[i]);
                }
            }
            else
            {
                int i = SQL.ExecuteSql("delete from B_news where n_id=" + id);
                if (i <= 0)
                {
                    Response.Write(function.alert_text(4, "删除失败", ""));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_news.html"));
        }

        /// <summary>
        /// 删除帮助信息
        /// </summary>
        /// <param name="id"></param>
        private void T_B_help(string id)
        {
            if (id == "" || id == null)
            {
                id = Request.Form["h_id"];
                if (id == "" || id == null)
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)
                {
                    SQL.ExecuteSql("delete from B_help where h_id=" + delid[i]);
                }
            }
            else
            {
                int i = SQL.ExecuteSql("delete from B_help where h_id=" + id);
                if (i <= 0)
                {
                    Response.Write(function.alert_text(4, "删除失败", ""));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_help.html"));
        }

        /// <summary>
        /// 删除帮助信息
        /// </summary>
        /// <param name="id"></param>
        private void T_B_help_all(string id)
        {
            if (id == "" || id == null)
            {
                //id = Request.Form["h_id"];

                id = string.Join(",", (string[])Request.Form.GetValues("checkbox"));

                if (id == "" || id == null)
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)
                {
                    SQL.ExecuteSql("delete from B_help where h_id=" + delid[i]);
                }
            }
            else
            {
                int i = SQL.ExecuteSql("delete from B_help where h_id=" + id);
                if (i <= 0)
                {
                    Response.Write(function.alert_text(4, "删除失败", ""));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_help.html"));
        }

        /// <summary>
        /// 删除搜索结果内容
        /// </summary>
        /// <param name="id"></param>
        private void T_B_search(string id)
        {
            if (id == "" || id == null)
            {
                id = Request.Form["s_id"];
                if (id == "" || id == null)
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)
                {
                    SQL.ExecuteSql("delete from B_searchTitel where s_id=" + delid[i]);
                }
            }
            else
            {
                int i = SQL.ExecuteSql("delete from B_searchTitel where s_id=" + id);
                if (i <= 0)
                {
                    Response.Write(function.alert_text(4, "删除失败", ""));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_search.html"));
        }
        /// <summary>
        /// 删除搜索结果内容
        /// </summary>
        /// <param name="id"></param>
        private void T_B_api(string id)
        {
            if (id == "" || id == null)
            {
                id = Request["s_id"];
                if (id == "" || id == null)
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)
                {
                    SQL.ExecuteSql("delete from B_api_data where a_id=" + delid[i]);
                }
            }
            else
            {
                int i = SQL.ExecuteSql("delete from B_api_data where a_id=" + id);
                if (i <= 0)
                {
                    Response.Write(function.alert_text(4, "删除失败", ""));
                    return;
                }
            }
            Response.Write(function.alert_text(2, "删除成功", "admin_url.aspx?template=template/t_admin_api.html"));
        }

        private void T_B_links(string id)
        {
            if (id == "" || id == null)
            {
                id = Request["l_id"];
                if (id == "" || id == null)
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)
                {
                    DataTable dt = SQL.GetList("select l_img from B_links where l_id=" + delid[i]).Tables[0];
                    string oldimg = "";
                    if (dt.Rows.Count > 0)
                    {
                        oldimg = dt.Rows[0][0].ToString();
                        try
                        {
                            System.IO.File.Delete(Server.MapPath(oldimg));
                        }
                        catch { }
                    }
                    SQL.ExecuteSql("delete from B_links where l_id = " + delid[i]);
                }
            }
            else
            {
                SQL.ExecuteSql("delete from B_links where l_id = " + id);
            }
            Response.Redirect("admin_url.aspx?template=template/t_admin_links.html");
        }
        

        private void T_B_links_all(string id)
        {
            if (id == "" || id == null)
            {
                //id = Request["l_id"];

                id = string.Join(",", (string[])Request.Form.GetValues("checkbox"));

                if (id == "" || id == null)
                {
                    Response.Write(function.alert_text(4, "删除失败，尚未选择数据！", ""));
                    return;
                }
                string[] delid = id.Split(',');
                for (int i = 0; i < delid.Length; i++)
                {
                    DataTable dt = SQL.GetList("select l_img from B_links where l_id=" + delid[i]).Tables[0];
                    string oldimg = "";
                    if (dt.Rows.Count > 0)
                    {
                        oldimg = dt.Rows[0][0].ToString();
                        try
                        {
                            System.IO.File.Delete(Server.MapPath(oldimg));
                        }
                        catch { }
                    }
                    SQL.ExecuteSql("delete from B_links where l_id = " + delid[i]);
                }
            }
            else
            {
                SQL.ExecuteSql("delete from B_links where l_id = " + id);
            }
            Response.Redirect("admin_url.aspx?template=template/t_admin_links.html");
        }
    }
}